<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    class HashTable {
      constructor() {
        this.table = new Array(137);
      }

      hash(string) {
        let total = 0;
        for (let i = 0; i < string.length; i++) {
          total += string.charCodeAt(i);
        }
        return total % this.table.length;
      }

      put(key, value) {
        let index = this.hash(key);
        this.table[index] = value;
      }

      get(key) {
        let index = this.hash(key);
        return this.table[index];
      }

      remove(key) {
        let index = this.hash(key);
        delete this.table[index];
      }
    }

    let hashtable = new HashTable();
    hashtable.put('apple', 'red');
    hashtable.put('banana', 'yellow');
    console.log(hashtable.get('apple')); // 输出red
    hashtable.remove('apple');
    console.log(hashtable.get('apple')); // 输出undefined

  </script>
</body>

</html>